<?php

namespace App\Models\Members;

use App\Models\Members;
use Illuminate\Database\Eloquent\Model;

class MemberPipeline extends Model
{
    private $pipelineType = [
        1 => '开启竞猜',
        2 => '修改房间名',
        3 => '修改昵称',
        4 => '购买竞猜',
        5 => '竞猜流拍',
        6 => '房主返现收益',
        7 => '团队各项总收益',
        8 => '出售商品',
        9 => '收益提现',
        10 => '金豆充值',
        11 => '购买商品',
        12 => '竞购返回开心果',
        13 => '收益转换金豆',
        14 => '团队收益',
        15 => '平级收益',
        16 => '深度收益',
        17 => '回购金豆充值',
        18 => '平台分红',
    ];
    //类型 1-开启竞猜 2-修改房间名 3-修改昵称 4-购买竞猜 5-竞猜流拍 6-房主返现收益 7-团队各项总收益  8- 出售商品 9-收益提现  10-金豆充值  11-购买商品 12-平台分红 13-收益转换金豆  14-团队收益  15-平级收益  16-深度收益  17 回购金豆充值

    protected $table = 'member_pipeline';

    protected $fillable = [
        'type','member_id','desc','money','money_type'
    ];

    public function member()
    {
        return $this->hasOne(Members::class,'id','member_id');
    }


    public function getTypeAttribute($value)
    {
        return $this->pipelineType[$value] ?? '未知';
    }

    /**
     * 插入流水表
     * @param $member_id  用户ID
     * @param $money 金额
     * @param $pipelineType  流水类型 1 开竞猜   2 修改房间名称  3购买竞猜商品   4 房间开奖返回收益  5 竞猜流派返回金豆
     * @param $desc  描述
     * @param $type 1 增加  2 减少
     * @param $money_type 1 金豆  2 百香果  3 收益
     */
    public static function MemberAddPipeline($member_id,$money,$pipelineType,$desc,$type = 1,$money_type = 1)
    {
        return self::create([
             'type' => $pipelineType,
             'member_id' => $member_id,
             'desc' => $desc,
             'money' => $type == 1 ? $money : -$money,
             'money_type' => $money_type
        ]);
    }
}
